package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.player.EarnSpeedModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.VipMgr;

import java.math.BigInteger;

/**
 * vip等级活动
 */
public class VipLevelActivityCondition extends BaseActivityCondition {

	public VipLevelActivityCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
		super(activityInfo, activityConditionInfo, baseActivityData);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.VipLevel.getValue(), handle);
	}

	@Override
	public void removeTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.VipLevel.getValue(), handle);
	}

	public boolean isCompleted(GamePlayer player) {
		return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
	}

	@Override
	public void initRechargeConditionData() {
		player.getModule(EarnSpeedModule.class).resetDay();
		if (getValue().compareTo(BigInteger.ZERO) == 0) {
			AttributeModule attributeModule = player.getModule(AttributeModule.class);
			long money = attributeModule.getAttribute(ePlayerAttrType.DayTotalRecharge);
			if (money > 0) {
				changeValue(VipMgr.getVipLv(player.getUserInfo().getVipExp()));
			}
		}
	}

	@Override
	protected void player_BoardLevelHandle(Object object) {
		int args = (int)object;
		setValue(BigInteger.valueOf(args));
	}

}
